package monitor;

import java.util.Date;
import java.util.List;

import jess.JessException;

import monitor.basic.Activity;
import monitor.basic.Monitor;
import monitor.inference.InferenceEngine;
import monitor.transmission.Transmitter;

import socio.Entity;
import socio.hardware.Door;
import socio.initiative.Human;
import socio.other.Direction;

public aspect DoorMonitor extends Monitor {
	public DoorMonitor() {
		super();
		try {
			InferenceEngine engine = new InferenceEngine(null, null);
			Transmitter transmitter = new Transmitter();
			this.setTransmitter(transmitter);
			this.setEngine(engine);
			this.start();
		} catch (JessException e) {
			e.printStackTrace();
		}
	}

	after(Door door, Human who, Date when) returning() : 
		execution(void Door.open(Human,Date))
		&&target(door)
		&&args(who,when) 
	{
		Activity activity = new Activity(who, "openned", door, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]the door is openned by"
				+ who.getId());
	}

	after(Door door, Human who, Date when) returning() : 
		execution(void Door.close(Human,Date))
		&&target(door)
		&&args(who,when) 
	{
		Activity activity = new Activity(who, "closed", door, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]the door is closed by"
				+ who.getId());
	}

	before(Door door, List<Entity> whos, Date when, Direction from, Direction to) : 
		execution(void Door.through(..))
		&&target(door)
		&&args(whos,when,from,to) 
	{
		this.recorder.record(new Activity(null, whos, "toGoThrough", door,
				when, from, to));
	}

	after(Door door, List<Entity> whos, Date when, Direction from, Direction to) returning() : 
		execution(void Door.through(..))
		&&target(door)
		&&args(whos,when,from,to) 
	{
		this.recorder.record(new Activity(null, whos, "wentThrough", door,
				when, from, to));
	}
}
